Skip to content

Enhancement lastUpdated cell styling #135

Merged
merged 22 commits into from
Jan 22, 2021
Merged

Conversation

wrigh393
Copy link
Collaborator

@wrigh393 wrigh393 commented Dec 3, 2020

No description provided.

@campb303
Copy link
Collaborator

campb303 commented Dec 3, 2020

Closes #90

Copy link
Collaborator

@campb303 campb303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically this works well. Formatting needs some work.

src/components/ItemTable/ItemTable.js Outdated Show resolved Hide resolved
return (
<TableCell
classes={classes}
{...reactTableCellProps} //expands table cell props to allow access to style props
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comment above line of code it applies to. Use a space between // and the start of the comment. Use proper sentence case with comments.

Suggested change
{...reactTableCellProps} //expands table cell props to allow access to style props
// Expands table cell props to allow access to style props.
{...reactTableCellProps}

<TableCell
classes={classes}
{...reactTableCellProps} //expands table cell props to allow access to style props
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move comment above line of code it applies to. Use a space between // and the start of the comment. Use proper sentence case with comments.

Suggested change
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling
// Expands style prop of table cell to allow addition of custom styling without losing default styling.
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }}

@@ -34,7 +65,8 @@ export default function ItemTable({ data }) {
borderLeftWidth: "1px",
borderLeftStyle: "solid",
borderColor: theme.palette.type === "light" ? theme.palette.grey[300] : theme.palette.grey[500]
}
},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary blank line.

@@ -48,7 +80,7 @@ export default function ItemTable({ data }) {
{ Header: 'Subject', accessor: 'subject' },
{ Header: 'Status', accessor: 'status', },
{ Header: 'Priority', accessor: 'priority' },
{ Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <RelativeTime value={value} /> },
{ Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <LastUpdatedCell time={value} /> },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Cell overrides because we're controlling them in the render statements below. The definitions here will never be used.

Comment on lines 110 to 111
<Table {...getTableProps}
aria-label="Table of Queue Items"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When splitting component props across multiple lines, do not include props on the same line as the opening tag.

Suggested change
<Table {...getTableProps}
aria-label="Table of Queue Items"
<Table
{...getTableProps}
aria-label="Table of Queue Items"

@@ -135,9 +170,24 @@ export default function ItemTable({ data }) {
selected={isSelected}
{...row.getRowProps()} >
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like with starting tags and multi-line props, place tag endings on their own line.

Suggested change
{...row.getRowProps()} >
{...row.getRowProps()}
>

</TableCell>

cell.render(
//conditonally renders custom cell component based on cell.column.id prop value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a space between // and the start of the comment. Use proper sentence case with comments.

Suggested change
//conditonally renders custom cell component based on cell.column.id prop value
// Conditonally renders custom cell component based on cell.column.id prop value.

Comment on lines 176 to 186
cell.column.id === "lastUpdated"
? <LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
:
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using multi line values for ternary operators, wrap the value for true and false in parenthesis.

Suggested change
cell.column.id === "lastUpdated"
? <LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
:
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
cell.column.id === "lastUpdated"
? (
<LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
)
: (
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
)

{cell.value}
</TableCell>
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra blank line.

@wrigh393 wrigh393 added frontend enhancement Request for a change to existing functionality high-priority Needs immediate extra focus labels Dec 3, 2020
Copy link
Collaborator

@campb303 campb303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks good. Needs refactoring.

Comment on lines 13 to 43
const LastUpdatedCell = ({ time, reactTableCellProps, classes }) => {
const lastUpdated = new Date(time).getTime();
const now = new Date().getTime();
const timeDelta = now - lastUpdated;
const day = 24 * 60 * 60 * 1000;
const week = day * 7;
const month = week * 4;

let backgroundColor = "white";
if (timeDelta > day && timeDelta <= week) {
backgroundColor = red[100]
}
else if (timeDelta > week && timeDelta <= month) {
backgroundColor = red[300]
}
else if (timeDelta > month) {
backgroundColor = red[500]
}

return (
<TableCell
classes={classes}
// Expands table cell props to allow access to style props.
{...reactTableCellProps}
// Expands style prop of table cell to allow addtion of custom styling without losing default styling.
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }}
>
<RelativeTime value={time} />
</TableCell>
);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is good. This should be its own component with docs. It should also extend an ItemTableCell (see comments below about ItemTableCell.)

Comment on lines 192 to 197
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
{cell.value}
</TableCell>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid WET (writing everything twice) code and keep it DRY (don't repeat yourself). We can do that here by making a component for a TableCell and giving it the CSS override equivalent to classes.columnBorders. It could be called something like ItemTableCell. Then we'd have one and only one place where we need to make styling changes.

Something like this could also be extended by the LastUpdatedCell so we're not duplicating logic.

@campb303 campb303 linked an issue Jan 4, 2021 that may be closed by this pull request
@campb303 campb303 self-assigned this Jan 5, 2021
@campb303 campb303 added this to the v1-readonly milestone Jan 5, 2021
@campb303
Copy link
Collaborator

A significant amount of work needed to be put in to resolve some logical, visual, and organizational issues.

Logical

With more than 2 options, ternary statements must be nested and this is difficult to read. switch statements and if/elif/else trees are better (in that order) for readability with multiple options. ItemTable's TableBody generation was updated to use a switch statement instead of nested ternary statements to improve readability.

The LastUpdatedCell had styling logic from the ItemTableCell duplicated unnecessarily which would lead to breaking changes in the future. The LastUpdatedCell is not effectively inheriting from the LastUpdatedCell to avoid this issue.

The logic in the LastUpdatedCell that determines the background color was moved to its own function to better isolate code fragments. This also made it easier to inset the background color into the styling info from React Table.

Visual

Because of inheritance and overriding issues with styling, the sizing style rules were not being correctly applied to the LastUpdatedCell. This was fixed by injecting backgroundColor into the props object passed from React Table.

Because LastUpdatedCell was duplicating ItemTableCell's border information, some borders were being doubled up. This was fixed with proper inheritance.

Organizational

Documentation for ItemTableCell and LastUpdatedCell were not created. This was done now but docs should always be made at the same time as the component.

Code formatting was inconsistent. This was fixed by using the jslint formatter from within VSCode.

@campb303 campb303 merged commit f3aa06f into staging Jan 22, 2021
Sign in to join this conversation on GitHub.
Labels
enhancement Request for a change to existing functionality high-priority Needs immediate extra focus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add coloring to ItemTable dates to indicate age
2 participants